package com.order.rec;

import com.order.food.domain.OrderFood;
import com.order.food.service.IOrderFoodService;
import com.order.promotion.domain.OrderPromotion;
import com.order.promotion.service.IOrderPromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


@Controller
public class RecIndexController {

    @Autowired
    private IOrderFoodService FoodService;

    @Autowired
    private IOrderPromotionService promotionservice;

    @Autowired
    private JavaMailSender javaMailSender;



    @GetMapping("/")
    public String recindex(Model m){

        //查询食品图片名字价格
        List<OrderFood> eo = FoodService.selectOrderFoodNamePrice();
        m.addAttribute("eo" ,eo);


        List<OrderFood> eo1 = FoodService.selectOrderFoodNamePrice1();
        m.addAttribute("eo1" ,eo1);




        return "rec/index";
    }

    @GetMapping("/about")
    public String about(){

        return "rec/about";
    }

    @GetMapping("/menu")
    public String menu( Model m){


        List<OrderFood> eo = FoodService.selectOrderFoodNamePrice2();
        m.addAttribute("eo" ,eo);

        return "rec/menu";
    }

    @GetMapping("/contact")
    public String contact(){

        return "rec/contact";
    }

    @GetMapping("/elements")
    public String elements(){

        return "rec/elements";
    }

    @GetMapping("/gallery")
    public String gallery(){

        return "rec/gallery";
    }

    @GetMapping("/caipu")
    public String caipu(Model m){

        List<OrderPromotion> eo = promotionservice.selectPromotionId();

        m.addAttribute("eo",eo);

        return "rec/caipu";
    }

    @GetMapping("/ditu")
    public String ditu(){

        return "rec/ditu";
    }

    @GetMapping("/bloghome")
    public String bloghome(){

        return "rec/bloghome";
    }

    @GetMapping("/blogsingle")
    public String blogsingle(){

        return "rec/blogsingle";
    }

    //contact页面邮箱验证
    @PostMapping("/call/mail")
    public String mail(@RequestParam String username,@RequestParam String email,@RequestParam String phone,@RequestParam String msg){
        String from = "2697691939@qq.com";// 发件人
        String to = email;// 收件人
        // String cc = "";// 抄送人
        String subject = username +"+" + phone;
        String content = msg + "上帝QAQ" + email;

        SimpleMailMessage simpMsg = new SimpleMailMessage();
        simpMsg.setFrom(from);
        simpMsg.setTo(to);
        simpMsg.setSubject(subject);
        simpMsg.setText(content);
        javaMailSender.send(simpMsg);
        return "rec/contact";
    }

}
